﻿#if UNITY_EDITOR
using Ease.EaseNode.Runtime;
using UnityEditor.Experimental.GraphView;

namespace Ease.EaseMission.Runtime
{
    
    public partial class MissionData
    {
        public override string Key => Id.ToString();

        private MissionNodeInfoConverter converter = null;

        private MissionNodeInfoConverter Converter
        {
            get
            {
                if (converter == null)
                    return new MissionNodeInfoConverter();
                return converter;
            }
        }

        protected override void OnNodeInfoInit()
        {
            NodeInfo.InputConfigs.Clear();
            NodeInfo.InputConfigs.Add(new PortConfig() {id = 0, capacity = Port.Capacity.Single, portName = "input"});
            NodeInfo.OutputConfigs.Clear();
            NodeInfo.OutputConfigs.Add(new PortConfig() {id = 0, capacity = Port.Capacity.Single, portName = "output"});
            NodeInfo.InputInfos.Clear();
            NodeInfo.InputInfos.AddRange(Converter.ToInputPortInfo(PreIds, Key));
            NodeInfo.OutputInfos.Clear();
            NodeInfo.OutputInfos.AddRange(Converter.ToOutputPortInfo(NextIds, Key));
        }

        protected override void OnNodeInfoChange()
        {
            PreIds.Clear();
            PreIds.AddRange(Converter.ToInputData(NodeInfo.InputInfos));
            NextIds.Clear();
            NextIds.AddRange(Converter.ToInputData(NodeInfo.OutputInfos));
        }
    }
#endif
}